<%@ page import="com.cinsea.htmlselect.service.OptionService" %>
<%@ page import="com.cinsea.common.Env" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ include file="/common/common.jsp" %>
<%--
  ~ Copyright (c) 2011. 晨熹软件版权所有。
  --%>

<%
    String processid=StringUtil.null2String(request.getParameter("processid"));
    //测试用processid="f2d1fb3e2d2d8113012d2d919edd0007";
    String teacherSql="select b.processid as id,b.name from ut_trainningcontent a,ut_teacher b where a.teacher=b.processid and iskp=1 and a.processid=?";
    JdbcDao jdbcDao=(JdbcDao)Env.getBean("jdbcDao");
    List teachers=jdbcDao.queryForList(teacherSql,new Object[]{processid}) ;
    String kc="、关于课程内容";
    String js="、讲师";
    String jx="、关于教学服务";
    String xy="、学员的感受";
    List<Option> kcOptions=optionService.getOptions("8a00010f2d5e315a012d72e0caaf01eb",null);
    List<Option> jsOptions=optionService.getOptions("8a00010f2d5e315a012d72e1601901ec",null);
    List<Option> jxOptions=optionService.getOptions("8a00010f2d5e315a012d72e19a0601ed",null);
    List<Option> xyOptions=optionService.getOptions("8a00010f2d5e315a012d72e1d76c01ee",null);
    int i =1;
    String kpiSql="";
    String k1="";
    String k2="";
    String k3="";
    String k4="";
    String k5="";
    String k6="";
    double k7=0;
    double k8=0;
    double s7=0;
    double s8=0;

	double kcmyd=0;
	double jsmyd=0;
	double hqmyd=0;
	int teachercnt=0;

	int cnt=0;
    pagemenustr += "addBtn(tb,'编辑','E','application_edit',function(){location='scoreedit.jsp?processid="+processid+"'});";
%>
<html>
<head>
    <%@ include file="/common/head.jsp" %>
    <style>
        .scoretable {border:1px solid #000}
    </style>
    <script type="text/javascript">
       Ext.onReady(function() {
            <%if(!pagemenustr.equals("")){%>
            var tb = new Ext.Toolbar();
            tb.render('pagemenubar');
            <%=pagemenustr%>
            <%}%>
       } )
    </script>
</head>
<body>
<div id="pagemenubar" style="z-index:100;"></div>
<table class=scoretable cellspacing="0" cellpadding="0" width="100%">
    <colgroup>
        <col width="30%">
        <col width="10%">
        <col width="10%">
        <col width="10%">
        <col width="10%">
        <col width="10%">
        <col width="10%">
        <col width="10%">
    </colgroup>
    <tr>
        <td>指标</td>
        <td>很好</td>
        <td>好</td>
        <td>一般</td>
        <td>差</td>
        <td>很差</td>
        <td>小计(一般以上)</td>
        <td>小计(一般及以下)</td>
    </tr>
    <tr bgcolor="graytext">
        <td><%=i+++kc%></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    <%for(Option kcOption:kcOptions){
         kpiSql="select * from ut_kpiscore where prjid=? and kid=?";
        List data=jdbcDao.queryForList(kpiSql,new Object[]{processid,kcOption.getId()});
        if (data.size()>0){
            k1=((Map)data.get(0)).get("k1")==null?"" :((Map)data.get(0)).get("k1").toString();					
            k2= ((Map)data.get(0)).get("k2")==null?"" :((Map)data.get(0)).get("k2").toString();
            k3= ((Map)data.get(0)).get("k3")==null?"" :((Map)data.get(0)).get("k3").toString();
            k4= ((Map)data.get(0)).get("k4")==null?"" :((Map)data.get(0)).get("k4").toString();
            k5= ((Map)data.get(0)).get("k5")==null?"" :((Map)data.get(0)).get("k5").toString();
            k6= ((Map)data.get(0)).get("k6")==null?"1" :((Map)data.get(0)).get("k6").toString();
            k7=MathUtil.round(((double)(NumberUtil.getIntegerValue(k1)+NumberUtil.getIntegerValue(k2))/NumberUtil.getIntegerValue(k6)),4);
			if(k7>0){
				cnt+=1;
				s7+=k7;
				k8=MathUtil.round(1-k7,4);
				s8+=k8;
			}else{
				k8=MathUtil.round(((double)(NumberUtil.getIntegerValue(k3)+NumberUtil.getIntegerValue(k4)+NumberUtil.getIntegerValue(k5))/NumberUtil.getIntegerValue(k6)),4);
				if(k8>0){
					cnt+=1;
					s8+=k8;
					k7=MathUtil.round(1-k8,4);
					s7+=k7;
				}
			}

        }
    %>
    <tr>
        <td><%=kcOption.getObjname()%></td>
        <td><%=k1%></td>
        <td><%=k2%></td>
        <td><%=k3%></td>
        <td><%=k4%></td>
        <td><%=k5%></td>
		<%if(k7>0){%>
		    <td><%=k7*100%>%</td>
		<%}else{%>
			<td></td>
		<%}%>
		<%if(k8>0){%>
		    <td><%=k8*100%>%</td>
		<%}else{%>
			<td></td>
		<%}%>
    </tr>
    <%}%>
    <tr>
        <td>小计aaa</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
		<%if(s7>0){kcmyd=MathUtil.round(s7*100/cnt,2);%>
		    <td><%=MathUtil.round(s7*100/cnt,2)%>%</td>
		<%}else{%>
			<td></td>
		<%}%>
		<%if(s8>0){%>
		    <td><%=MathUtil.round(s8*100/cnt,2)%>%</td>
		<%}else{%>
			<td></td>
		<%}%>
    </tr>

   <%for(Object t:teachers){
        s7=0;
        s8=0;
       String tid=((Map)t).get("id").toString();
       String tname= ((Map)t).get("name").toString();
	   cnt=0;
   %>
    <tr bgcolor="graytext">
        <td><%=i+++js+tname%></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    <% for(Option jsOption:jsOptions){
     kpiSql="select * from ut_kpiscore where prjid=? and teacherid=? and  kid=?";
        List data=jdbcDao.queryForList(kpiSql,new Object[]{processid,tid,jsOption.getId()});
        if (data.size()>0){
            k1= ((Map)data.get(0)).get("k1")==null?"" :((Map)data.get(0)).get("k1").toString();
            k2= ((Map)data.get(0)).get("k2")==null?"" :((Map)data.get(0)).get("k2").toString();
            k3= ((Map)data.get(0)).get("k3")==null?"" :((Map)data.get(0)).get("k3").toString();
            k4= ((Map)data.get(0)).get("k4")==null?"" :((Map)data.get(0)).get("k4").toString();
            k5= ((Map)data.get(0)).get("k5")==null?"" :((Map)data.get(0)).get("k5").toString();
            k6= ((Map)data.get(0)).get("k6")==null?"1" :((Map)data.get(0)).get("k6").toString();
			
			k7=MathUtil.round(((double)(NumberUtil.getIntegerValue(k1)+NumberUtil.getIntegerValue(k2))/NumberUtil.getIntegerValue(k6)),4);
			if(k7>0){
				cnt+=1;
				s7+=k7;
				k8=MathUtil.round(1-k7,4);
				s8+=k8;
			}else{
				k8=MathUtil.round(((double)(NumberUtil.getIntegerValue(k3)+NumberUtil.getIntegerValue(k4)+NumberUtil.getIntegerValue(k5))/NumberUtil.getIntegerValue(k6)),4);
				if(k8>0){
					cnt+=1;
					s8+=k8;
					k7=MathUtil.round(1-k8,4);
					s7+=k7;
				}
			}
        }
    %>
    <tr>
        <td><%=jsOption.getObjname()%></td>
        <td><%=k1%></td>
        <td><%=k2%></td>
        <td><%=k3%></td>
        <td><%=k4%></td>
        <td><%=k5%></td>
		<%if(k7>0){%>
		    <td><%=k7*100%>%</td>
		<%}else{%>
			<td></td>
		<%}%>
		<%if(k8>0){%>
		    <td><%=k8*100%>%</td>
		<%}else{%>
			<td></td>
		<%}%>
    </tr>
    <%}%>
    <tr>
        <td>小计bbb</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
		<%if(cnt==0) cnt=1;%>
		<%if(s7>0){jsmyd+=MathUtil.round(s7*100/cnt,2);teachercnt++;%>
		    <td><%=MathUtil.round(s7*100/cnt,2)%>%</td>
		<%}else{%>
			<td></td>
		<%}%>
		<%if(s8>0){%>
		    <td><%=MathUtil.round(s8*100/cnt,2)%>%</td>
		<%}else{%>
			<td></td>
		<%}%>
    </tr>
    <%}%>

    <tr bgcolor="graytext">
        <td><%=i+++jx%></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    <%  s7=0;
    s8=0;
	cnt=0;
        for(Option jxOption:jxOptions){
        kpiSql="select * from ut_kpiscore where prjid=? and kid=?";
        List data=jdbcDao.queryForList(kpiSql,new Object[]{processid,jxOption.getId()});
        if (data.size()>0){
            k1= ((Map)data.get(0)).get("k1")==null?"" :((Map)data.get(0)).get("k1").toString();
            k2= ((Map)data.get(0)).get("k2")==null?"" :((Map)data.get(0)).get("k2").toString();
            k3= ((Map)data.get(0)).get("k3")==null?"" :((Map)data.get(0)).get("k3").toString();
            k4= ((Map)data.get(0)).get("k4")==null?"" :((Map)data.get(0)).get("k4").toString();
            k5= ((Map)data.get(0)).get("k5")==null?"" :((Map)data.get(0)).get("k5").toString();
            k6= ((Map)data.get(0)).get("k6")==null?"1" :((Map)data.get(0)).get("k6").toString();
            k7=MathUtil.round(((double)(NumberUtil.getIntegerValue(k1)+NumberUtil.getIntegerValue(k2))/NumberUtil.getIntegerValue(k6)),4);
            if(!jxOption.getId().equals("8a00010f2d5e315a012d72e9dc96021a")){   //班主任
				if(k7>0){
					cnt+=1;
					s7+=k7;
					k8=MathUtil.round(1-k7,4);
					s8+=k8;
				}else{
					k8=MathUtil.round(((double)(NumberUtil.getIntegerValue(k3)+NumberUtil.getIntegerValue(k4)+NumberUtil.getIntegerValue(k5))/NumberUtil.getIntegerValue(k6)),4);
					if(k8>0){
						cnt+=1;
						s8+=k8;
						k7=MathUtil.round(1-k8,4);
						s7+=k7;
					}
				}
			}
        }
    %>
    <tr>
        <td><%=jxOption.getObjname()%></td>
        <td><%=k1%></td>
        <td><%=k2%></td>
        <td><%=k3%></td>
        <td><%=k4%></td>
        <td><%=k5%></td>
		<%if(k7>0){%>
		    <td><%=k7*100%>%</td>
		<%}else{%>
			<td></td>
		<%}%>
		<%if(k8>0){%>
		    <td><%=k8*100%>%</td>
		<%}else{%>
			<td></td>
		<%}%>
    </tr>
    <%}%>
    <tr>
        <td>小计ccc</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
		<%if(cnt==0) cnt=1;%>
		<%if(s7>0){hqmyd+=MathUtil.round(s7*100/cnt,2);%>
		    <td><%=MathUtil.round(s7*100/cnt,2)%>%</td>
		<%}else{%>
			<td></td>
		<%}%>
		<%if(s8>0){%>
		    <td><%=MathUtil.round(s8*100/cnt,2)%>%</td>
		<%}else{%>
			<td></td>
		<%}%>
    </tr>
    <tr bgcolor="graytext">
        <td><%=i+++xy%></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    <%  s7=0;
    s8=0;
	cnt=0;
        for(Option xyOption:xyOptions){
    kpiSql="select * from ut_kpiscore where prjid=? and kid=?";
        List data=jdbcDao.queryForList(kpiSql,new Object[]{processid,xyOption.getId()});
    if (data.size()>0){
            k1= ((Map)data.get(0)).get("k1")==null?"" :((Map)data.get(0)).get("k1").toString();
            k2= ((Map)data.get(0)).get("k2")==null?"" :((Map)data.get(0)).get("k2").toString();
            k3= ((Map)data.get(0)).get("k3")==null?"" :((Map)data.get(0)).get("k3").toString();
            k4= ((Map)data.get(0)).get("k4")==null?"" :((Map)data.get(0)).get("k4").toString();
            k5= ((Map)data.get(0)).get("k5")==null?"" :((Map)data.get(0)).get("k5").toString();
            k6= ((Map)data.get(0)).get("k6")==null?"1" :((Map)data.get(0)).get("k6").toString();
			
			k7=MathUtil.round(((double)(NumberUtil.getIntegerValue(k1)+NumberUtil.getIntegerValue(k2))/NumberUtil.getIntegerValue(k6)),4);
			if(k7>0){
				cnt+=1;
				s7+=k7;
				k8=MathUtil.round(1-k7,4);
				s8+=k8;
			}else{
				k8=MathUtil.round(((double)(NumberUtil.getIntegerValue(k3)+NumberUtil.getIntegerValue(k4)+NumberUtil.getIntegerValue(k5))/NumberUtil.getIntegerValue(k6)),4);
				if(k8>0){
					cnt+=1;
					s8+=k8;
					k7=MathUtil.round(1-k8,4);
					s7+=k7;
				}
			}
        }%>
    <tr>
        <td><%=xyOption.getObjname()%></td>
        <td><%=k1%></td>
        <td><%=k2%></td>
        <td><%=k3%></td>
        <td><%=k4%></td>
        <td><%=k5%></td>
		<%if(k7>0){%>
		    <td><%=k7*100%>%</td>
		<%}else{%>
			<td></td>
		<%}%>
		<%if(k8>0){%>
		    <td><%=k8*100%>%</td>
		<%}else{%>
			<td></td>
		<%}%>
    </tr>
    <%} %>
    <tr>
        <td>小计</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
		<%if(cnt==0) cnt=1;%>
		<%if(s7>0){%>
		    <td><%=MathUtil.round(s7*100/cnt,2)%>%</td>
		<%}else{%>
			<td></td>
		<%}%>
		<%if(s8>0){%>
		    <td><%=MathUtil.round(s8*100/cnt,2)%>%</td>
		<%}else{%>
			<td></td>
		<%}
		
		%>
    </tr>
</table>
</body>
</html>
<%
out.flush();
if(cnt>0) jsmyd=jsmyd/teachercnt;
 jdbcDao.update("update ut_prj set kcmyd="+kcmyd+",jsmyd="+jsmyd+",hqmyd="+hqmyd+" where processid='"+processid+"'");	
%>
